#ifndef __RINGBUFFER_H
#define __RINGBUFFER_H
#include "stdtype.h"

/* no data */
#define MX_RINGBUFFER_NULL  -1

/**
 * ring buffer struct definition
 */
typedef struct mx_ringbuffer
{
    mx_bool_t hit;
    mx_usize_t wpointer;
    mx_usize_t rpointer;
    mx_usize_t size;
    mx_uint8_pt buffer;
} mx_ringbuffer_t, *mx_ringbuffer_pt;

/* initialize the specified ringbuffer */
void mx_ringbuffer_init (mx_ringbuffer_pt prbuf, mx_uint8_pt buf, mx_usize_t size);
/* put a char data to ringbuffer */
void mx_ringbuffer_putchar (mx_ringbuffer_pt prbuf, mx_uint8_t data);
/* get a char data from the ringbuffer */
mx_int16_t mx_ringbuffer_getchar (mx_ringbuffer_pt prbuf);
/* calculate the effective data length of the ringbuffer */
mx_usize_t mx_ringbuffer_count (mx_ringbuffer_pt prbuf);
/* get all the effective data from ringbuffer */
mx_usize_t mx_ringbuffer_getall (mx_ringbuffer_pt prbuf, mx_uint8_pt arr);
/* clear(reset) the ringbuffer */
void mx_ringbuffer_clear (mx_ringbuffer_pt prbuf);
/* delete last puted data */
void mx_ringbuffer_backspace (mx_ringbuffer_pt prbuf, mx_usize_t backnum);

#endif
